module serial_rx (
  dout,  // Output Value
  clk,    // Clock
  rst,    // Reset
  rx  // Input receiver value
  );
  
  
output [3:0] dout;
input clk;
input rst;
input rx;

reg [3:0] dout;

reg [3:0] current_state, next_state;  // state variable

parameter idle=0,s0=1, s1=2, s2=3, s3=4,s4=5,s5=6,s6=7,s7=8,stop=9;

always @(state) 
  begin
    case (state)
    s0:
      dout[0] = rx;
    s1:
      dout[1] = rx;
    s2:
      dout[2] = rx;
    s3:
      dout[3] = rx;
    s4:
      dout[4] = rx;
    s5:
      dout[5] = rx;
    s6:
      dout[6] = rx;
    s7:
      dout[7] = rx;
  endcase
end

always @(posedge clk)
begin
  if (rst == 0)
    state = idle;
  else
    case (state)
      idle:
		state = s0;
      s0:
		state = s1;
      s1:
		state = s2;
      s2:
        state = s3;
      s3:
		state = s4;
      s4:
		state = s5;
      s5:
		state = s6;
      s7:
		state = stop;
      stop:
		state = idle;
      default:
      	state=idle;
    endcase
end

endmodule